
$(window).on("load", function () {
	$('#preloader').fadeOut('slow', function () {
		$(this).remove();
	});
});

var myscroll={
	node:null,
	flag:0,//0pc 1mob
	data:[],
	init: function (obj) {
		this.node = $(obj.node);
		this.data=obj.data;
        this.flag=$(window).width()<767?1:0;
		this.render();
	},
	render:function(){
		var html='<div class="swiper-wrapper">'
		for(var i=0;i<this.data.length;i++){		 
			html+='<div class="swiper-slide">';
			if(this.data[i].link==''){
				html+='<a href="javascript:;">'
			}else{
				html+='<a href="'+this.data[i].link+'" target="_blank">'
			}
			if(this.flag==0){
				html+='<div class="banner-bg" style="background-image:url('+this.data[i].pcSrc+')">\
                   <h2>'+this.data[i].txt+'</h2>\
				</div>'
			}else{
				html+='<div class="banner-bg" style="background-image:url('+this.data[i].mobSrc+')">\
                   <h2>'+this.data[i].txt+'</h2>\
				</div>'
			}

			
		html+='</a></div>'
		}		
	html+='</div>\
	<div class="swiper-pagination"></div>\
	<div class="swiper-button-prev"></div>\
	<div class="swiper-button-next"></div>'
	this.node.empty().append(html);
	this.setBannerHeight();
	},
	setBannerHeight:function(){
		var ww=$(window).width();
		var bh=400;
		if(ww<767){
         bh=1080*ww/1920;
		}else{
		 bh=700*ww/1920;
		}
		$('.banner-bg').css({height:bh+'px'})
	}
}
$(function () {    
    
	$('.live-iframe').each(function(){
        var ww=$(this).width();
		var hh=16*ww/9;
		$(this).find('iframe').height(hh);
	})
	$('.more a').click(function () {
		$(this).html('加载中...')
		$(this).addClass('is-disabled')
	})
	
	
	$('.swiper-video').each(function(i){
		new Swiper('.myswiper'+i+' .swiper', {
				freeMode: true,
				mousewheel: true,
				slidesPerView: "auto",
				freeModeMomentumRatio: 0.5,
			});
	})
	
	var nav_idx = parseInt(getQueryString('idx'))||0;
	let navScroll = new Swiper('.my-nav .swiper',{
		freeMode: true,
		slidesPerView: "auto",
		freeModeMomentumRatio: 0.5,
	});
	navScroll.slideTo(nav_idx)
	$('.my-nav').find('.swiper-slide:eq(' + nav_idx + ')').addClass('active')
	let typeScroll = new Swiper('.type-menu-wrap .swiper', {
		freeMode: true,
		slidesPerView: "auto",
		freeModeMomentumRatio: 0.5,
		on: {
			//当前swiper-slide点击时触发事件
			click: function (e) {
				var typeIndex = typeScroll.clickedIndex; // 当前点击按钮的下标
				$('.type-menu-wrap .swiper-slide').find('a').removeClass('active');
				$('.type-menu-wrap .swiper-slide').eq(typeIndex).find('a').addClass('active');
				let thisWidth = this.clickedSlide.offsetWidth;
				let thisLeft = this.clickedSlide.offsetLeft;
				let offsetX = this.width / 2 - thisLeft - thisWidth / 2;
				//偏移量在1/2视口内时，容器不发生偏移
				if (offsetX > 0) {
					offsetX = 0;
				}
				//offsetX小于容器最大偏移时，让偏移量等于容器最大的偏移量
				else if (offsetX < this.maxTranslate()) {
					offsetX = this.maxTranslate();
				}
				//设置容器的过渡动画
				this.setTransition(300);
				this.setTranslate(offsetX);
			}
		}
	});

	setTimeout(function () {
		$('#preloader').fadeOut('slow', function () {
			$(this).remove();
		});
	}, 500);
    

	$(document).on('click','.live-wrap .iconbofang',function(){
		var $par=$(this).closest('.live-wrap');		
		$(this).removeClass('iconbofang').addClass('iconzanting');
		var $video=$par.find('video');
		$video[0].play();
	})

	$(document).on('click','.live-wrap .iconzanting',function(){
		var $par=$(this).closest('.live-wrap');
		$(this).removeClass('iconzanting').addClass('iconbofang')
		var $video=$par.find('video');
		$video[0].pause();
	})

	//点击菜单
	// $('.my-nav').find('a').each(function () {
	// 	var href = $(this).attr("href");
	// 	if (href == window.location.href.indexOf(href) > -1 || document.location.href.search(href) >= 0) {
	// 		$(this).parent().addClass('active');
	// 	}
	// });


	//语言选择
	$('.info_languages li').click(function () {
		var $par = $(this).closest('.info_languages');
		var $txt = $par.find('>a .dropdown_text');
		$txt.text($(this).find('.dropdown_text').text());
	})


	function getQueryString(paramKey) {
		var reg = new RegExp("(^|&)" + paramKey + "=([^&]*)(&|$)");
		var paramValue = window.location.search.substr(1).match(reg);
		if (paramValue != null) return paramValue[2];
		return '';
	}
   
	

})